diff options
Diffstat (limited to 'src/pages/posts/[...slug].astro')
| -rw-r--r-- | src/pages/posts/[...slug].astro | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 76e4f28..b66d911 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -1,24 +1,27 @@ --- import { render } from "astro:content"; import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; -import { getAllPosts } from "@/data/post"; +import { getAllPosts, getPostNavigation } from "@/data/post"; import PostLayout from "@/layouts/BlogPost.astro"; // if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr export const getStaticPaths = (async () => { const blogEntries = await getAllPosts(true); // Include archived posts for direct access - return blogEntries.map((post) => ({ - params: { slug: post.id }, - props: { post }, - })); + return blogEntries.map((post) => { + const { prevPost, nextPost } = getPostNavigation(blogEntries, post); + return { + params: { slug: post.id }, + props: { post, prevPost, nextPost }, + }; + }); }) satisfies GetStaticPaths; type Props = InferGetStaticPropsType<typeof getStaticPaths>; -const { post } = Astro.props; +const { post, prevPost, nextPost } = Astro.props; const { Content } = await render(post); --- -<PostLayout post={post}> +<PostLayout post={post} prevPost={prevPost} nextPost={nextPost}> <Content /> </PostLayout> |
